﻿Imports System.Text

Namespace DotNetNuke.Modules.ActiveForums.Controls
    Public Class Ratings
        Public Property TopicId() As Integer = -1
        Public Property Enabled() As Boolean = False
        Public Property Rating() As Integer = -1
        Sub New(ByVal t As Integer, ByVal enable As Boolean, ByVal r As Integer)
            TopicId = t
            Enabled = enable
            Rating = r
        End Sub
        Public Function Render() As String
            Dim sb As New StringBuilder
            If Rating = -1 Then
                Rating = DataProvider.Instance.Topics_GetRating(TopicId)
            End If
            If Enabled Then
                sb.Append("<ul id=""af-rater"" class=""af-rater ")
            Else
                sb.Append("<ul class=""af-rater ")
            End If

            If Rating > 0 Then
                sb.Append(" rate" & Rating.ToString)
            End If
            sb.Append(""">")
            If Enabled Then
                sb.Append("<li onmouseover=""amaf_hoverRate(this,1);"" onmouseout=""amaf_hoverRate(this);"" onclick=""amaf_changeRate(1," & TopicId.ToString & ");"">&nbsp;</li>")
                sb.Append("<li onmouseover=""amaf_hoverRate(this,2);"" onmouseout=""amaf_hoverRate(this);"" onclick=""amaf_changeRate(2," & TopicId.ToString & ");"">&nbsp;</li>")
                sb.Append("<li onmouseover=""amaf_hoverRate(this,3);"" onmouseout=""amaf_hoverRate(this);"" onclick=""amaf_changeRate(3," & TopicId.ToString & ");"">&nbsp;</li>")
                sb.Append("<li onmouseover=""amaf_hoverRate(this,4);"" onmouseout=""amaf_hoverRate(this);"" onclick=""amaf_changeRate(4," & TopicId.ToString & ");"">&nbsp;</li>")
                sb.Append("<li onmouseover=""amaf_hoverRate(this,5);"" onmouseout=""amaf_hoverRate(this);"" onclick=""amaf_changeRate(5," & TopicId.ToString & ");"">&nbsp;</li>")
            Else
                sb.Append("<li>&nbsp;</li>")
                sb.Append("<li>&nbsp;</li>")
                sb.Append("<li>&nbsp;</li>")
                sb.Append("<li>&nbsp;</li>")
                sb.Append("<li>&nbsp;</li>")
            End If
            
            sb.Append("</ul>")
            If Enabled Then
                sb.Append("<input type=""hidden"" value=""" & Rating.ToString & """ id=""af-rate-value"" />")
            End If

            Return sb.ToString
        End Function
    End Class
End Namespace

